{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4/4 [==============================] - 0s 1ms/step - loss: 0.3906\n",
      "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/resource_variable_ops.py:1817: calling BaseResourceVariable.__init__ (from tensorflow.python.ops.resource_variable_ops) with constraint is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "If using Keras pass *_constraint arguments to layers.\n",
      "INFO:tensorflow:Assets written to: my_model/1/assets\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "import tensorflow as tf\n",
    "from tensorflow import keras\n",
    "\n",
    "def get_model():\n",
    "    # Create a simple model.\n",
    "    inputs = keras.Input(shape=(32,))\n",
    "    outputs = keras.layers.Dense(1)(inputs)\n",
    "    model = keras.Model(inputs, outputs)\n",
    "    model.compile(optimizer=\"adam\", loss=\"mean_squared_error\")\n",
    "    return model\n",
    "\n",
    "\n",
    "model = get_model()\n",
    "\n",
    "# Train the model.\n",
    "test_input = np.random.random((128, 32))\n",
    "test_target = np.random.random((128, 1))\n",
    "model.fit(test_input, test_target)\n",
    "\n",
    "# Calling `save('my_model')` creates a SavedModel folder `my_model`.\n",
    "model.save(\"my_model/1\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Model: \"model\"\n",
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "input_1 (InputLayer)         [(None, 32)]              0         \n",
      "_________________________________________________________________\n",
      "dense (Dense)                (None, 1)                 33        \n",
      "=================================================================\n",
      "Total params: 33\n",
      "Trainable params: 33\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n"
     ]
    }
   ],
   "source": [
    "# model.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "MetaGraphDef with tag-set: 'serve' contains the following SignatureDefs:\n",
      "\n",
      "signature_def['__saved_model_init_op']:\n",
      "  The given SavedModel SignatureDef contains the following input(s):\n",
      "  The given SavedModel SignatureDef contains the following output(s):\n",
      "    outputs['__saved_model_init_op'] tensor_info:\n",
      "        dtype: DT_INVALID\n",
      "        shape: unknown_rank\n",
      "        name: NoOp\n",
      "  Method name is: \n",
      "\n",
      "signature_def['serving_default']:\n",
      "  The given SavedModel SignatureDef contains the following input(s):\n",
      "    inputs['input_1'] tensor_info:\n",
      "        dtype: DT_FLOAT\n",
      "        shape: (-1, 32)\n",
      "        name: serving_default_input_1:0\n",
      "  The given SavedModel SignatureDef contains the following output(s):\n",
      "    outputs['dense'] tensor_info:\n",
      "        dtype: DT_FLOAT\n",
      "        shape: (-1, 1)\n",
      "        name: StatefulPartitionedCall:0\n",
      "  Method name is: tensorflow/serving/predict\n",
      "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/resource_variable_ops.py:1817: calling BaseResourceVariable.__init__ (from tensorflow.python.ops.resource_variable_ops) with constraint is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "If using Keras pass *_constraint arguments to layers.\n",
      "\n",
      "Defined Functions:\n",
      "  Function Name: '__call__'\n",
      "    Option #1\n",
      "      Callable with:\n",
      "        Argument #1\n",
      "          inputs: TensorSpec(shape=(None, 32), dtype=tf.float32, name='inputs')\n",
      "        Argument #2\n",
      "          DType: bool\n",
      "          Value: False\n",
      "        Argument #3\n",
      "          DType: NoneType\n",
      "          Value: None\n",
      "    Option #2\n",
      "      Callable with:\n",
      "        Argument #1\n",
      "          input_1: TensorSpec(shape=(None, 32), dtype=tf.float32, name='input_1')\n",
      "        Argument #2\n",
      "          DType: bool\n",
      "          Value: False\n",
      "        Argument #3\n",
      "          DType: NoneType\n",
      "          Value: None\n",
      "    Option #3\n",
      "      Callable with:\n",
      "        Argument #1\n",
      "          inputs: TensorSpec(shape=(None, 32), dtype=tf.float32, name='inputs')\n",
      "        Argument #2\n",
      "          DType: bool\n",
      "          Value: True\n",
      "        Argument #3\n",
      "          DType: NoneType\n",
      "          Value: None\n",
      "    Option #4\n",
      "      Callable with:\n",
      "        Argument #1\n",
      "          input_1: TensorSpec(shape=(None, 32), dtype=tf.float32, name='input_1')\n",
      "        Argument #2\n",
      "          DType: bool\n",
      "          Value: True\n",
      "        Argument #3\n",
      "          DType: NoneType\n",
      "          Value: None\n",
      "\n",
      "  Function Name: '_default_save_signature'\n",
      "    Option #1\n",
      "      Callable with:\n",
      "        Argument #1\n",
      "          input_1: TensorSpec(shape=(None, 32), dtype=tf.float32, name='input_1')\n",
      "\n",
      "  Function Name: 'call_and_return_all_conditional_losses'\n",
      "    Option #1\n",
      "      Callable with:\n",
      "        Argument #1\n",
      "          input_1: TensorSpec(shape=(None, 32), dtype=tf.float32, name='input_1')\n",
      "        Argument #2\n",
      "          DType: bool\n",
      "          Value: False\n",
      "        Argument #3\n",
      "          DType: NoneType\n",
      "          Value: None\n",
      "    Option #2\n",
      "      Callable with:\n",
      "        Argument #1\n",
      "          input_1: TensorSpec(shape=(None, 32), dtype=tf.float32, name='input_1')\n",
      "        Argument #2\n",
      "          DType: bool\n",
      "          Value: True\n",
      "        Argument #3\n",
      "          DType: NoneType\n",
      "          Value: None\n",
      "    Option #3\n",
      "      Callable with:\n",
      "        Argument #1\n",
      "          inputs: TensorSpec(shape=(None, 32), dtype=tf.float32, name='inputs')\n",
      "        Argument #2\n",
      "          DType: bool\n",
      "          Value: False\n",
      "        Argument #3\n",
      "          DType: NoneType\n",
      "          Value: None\n",
      "    Option #4\n",
      "      Callable with:\n",
      "        Argument #1\n",
      "          inputs: TensorSpec(shape=(None, 32), dtype=tf.float32, name='inputs')\n",
      "        Argument #2\n",
      "          DType: bool\n",
      "          Value: True\n",
      "        Argument #3\n",
      "          DType: NoneType\n",
      "          Value: None\n"
     ]
    }
   ],
   "source": [
    "!saved_model_cli show --dir my_model/1 --all"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "deb http://storage.googleapis.com/tensorflow-serving-apt stable tensorflow-model-server tensorflow-model-server-universal\n",
      "  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current\n",
      "                                 Dload  Upload   Total   Spent    Left  Speed\n",
      "100  2943  100  2943    0     0   3706      0 --:--:-- --:--:-- --:--:--  3706\n",
      "OK\n",
      "Hit:1 http://storage.googleapis.com/tensorflow-serving-apt stable InRelease\n",
      "Get:2 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]    \u001b[0m\u001b[33m\u001b[33m\n",
      "Hit:3 http://archive.ubuntu.com/ubuntu bionic InRelease                        \u001b[0m\n",
      "Get:4 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]      \u001b[0m\u001b[33m\u001b[33m\n",
      "Get:6 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]    \u001b[0m\u001b[33m\u001b[33m\u001b[33m\n",
      "Ign:5 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  InRelease33m\u001b[33m\u001b[33m\n",
      "Ign:7 https://developer.download.nvidia.cn/compute/machine-learning/repos/ubuntu1804/x86_64  InRelease\n",
      "Get:8 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  Release [697 B]\n",
      "Get:9 https://developer.download.nvidia.cn/compute/machine-learning/repos/ubuntu1804/x86_64  Release [564 B]\n",
      "Get:10 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  Release.gpg [836 B]\n",
      "Err:10 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  Release.gpg\n",
      "  The following signatures were invalid: BADSIG F60F4B3D7FA2AF80 cudatools <cudatools@nvidia.com>\n",
      "Get:11 https://developer.download.nvidia.cn/compute/machine-learning/repos/ubuntu1804/x86_64  Release.gpg [833 B]\n",
      "Get:12 https://developer.download.nvidia.cn/compute/machine-learning/repos/ubuntu1804/x86_64  Packages [43.7 kB]\n",
      "Fetched 297 kB in 15s (20.0 kB/s)                                              \u001b[0m\u001b[33m\n",
      "Reading package lists... Done\n",
      "Building dependency tree       \n",
      "Reading state information... Done\n",
      "64 packages can be upgraded. Run 'apt list --upgradable' to see them.\n",
      "W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  Release: The following signatures were invalid: BADSIG F60F4B3D7FA2AF80 cudatools <cudatools@nvidia.com>\n",
      "W: Failed to fetch https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/Release.gpg  The following signatures were invalid: BADSIG F60F4B3D7FA2AF80 cudatools <cudatools@nvidia.com>\n",
      "W: Some index files failed to download. They have been ignored, or old ones used instead.\n"
     ]
    }
   ],
   "source": [
    "# This is the same as you would do from your command line, but without the [arch=amd64], and no sudo\n",
    "# You would instead do:\n",
    "# echo \"deb [arch=amd64] http://storage.googleapis.com/tensorflow-serving-apt stable tensorflow-model-server tensorflow-model-server-universal\" | sudo tee /etc/apt/sources.list.d/tensorflow-serving.list && \\\n",
    "# curl https://storage.googleapis.com/tensorflow-serving-apt/tensorflow-serving.release.pub.gpg | sudo apt-key add -\n",
    "\n",
    "!echo \"deb http://storage.googleapis.com/tensorflow-serving-apt stable tensorflow-model-server tensorflow-model-server-universal\" | tee /etc/apt/sources.list.d/tensorflow-serving.list && \\\n",
    "curl https://storage.googleapis.com/tensorflow-serving-apt/tensorflow-serving.release.pub.gpg | apt-key add -\n",
    "!apt update"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reading package lists... Done\n",
      "Building dependency tree       \n",
      "Reading state information... Done\n",
      "tensorflow-model-server is already the newest version (2.2.0).\n",
      "0 upgraded, 0 newly installed, 0 to remove and 64 not upgraded.\n"
     ]
    }
   ],
   "source": [
    "!apt-get install tensorflow-model-server"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# tensorflow_model_server   --rest_api_port=8501   --model_base_path=\"/tf/develop/tensorflow-101/experts/code_sample/chapter-7/my_model\" --model_name=test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Data: {\"signature_name\": \"serving_default\", \"instances\": ... 936144825, 0.5185309751828353, 0.5023908954318431]]}\n"
     ]
    }
   ],
   "source": [
    "import json\n",
    "\n",
    "test_input = np.random.random((10, 32)).tolist()\n",
    "\n",
    "data = json.dumps({\"signature_name\": \"serving_default\", \"instances\": test_input})\n",
    "print('Data: {} ... {}'.format(data[:50], data[len(data)-52:]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[[0.45436844163230994,\n",
       "  0.05627256599276975,\n",
       "  0.25591809270793164,\n",
       "  0.029789544486036323,\n",
       "  0.39569255510939494,\n",
       "  0.7297838401133463,\n",
       "  0.23742993456288586,\n",
       "  0.8996363303931911,\n",
       "  0.29382635031297666,\n",
       "  0.025774003317361016,\n",
       "  0.8040641769271422,\n",
       "  0.06950509753452039,\n",
       "  0.21925935817381603,\n",
       "  0.18863782598441936,\n",
       "  0.5805749762694452,\n",
       "  0.6769084977837265,\n",
       "  0.47579473171726316,\n",
       "  0.5773005191777567,\n",
       "  0.6531662164542267,\n",
       "  0.25186803066891195,\n",
       "  0.7913387473230628,\n",
       "  0.4020227463536963,\n",
       "  0.8157617668025108,\n",
       "  0.8195900085845316,\n",
       "  0.7934095541761969,\n",
       "  0.9492209943467972,\n",
       "  0.6250450461649494,\n",
       "  0.3630605771474398,\n",
       "  0.7624501040854188,\n",
       "  0.924706956593921,\n",
       "  0.6132740724949204,\n",
       "  0.08585189124069181],\n",
       " [0.23367816864056,\n",
       "  0.46511921932905587,\n",
       "  0.8163823421097941,\n",
       "  0.147512006689263,\n",
       "  0.20003473397265437,\n",
       "  0.9470153352191873,\n",
       "  0.1524467815969739,\n",
       "  0.26541536364364526,\n",
       "  0.17331656425344633,\n",
       "  0.8850017191250238,\n",
       "  0.0043885991971420735,\n",
       "  0.23702160657698235,\n",
       "  0.3992559161075335,\n",
       "  0.1302737575544446,\n",
       "  0.08806622406499554,\n",
       "  0.9536338387299371,\n",
       "  0.735959764520001,\n",
       "  0.7571310076856771,\n",
       "  0.6025014192474702,\n",
       "  0.6428223513586394,\n",
       "  0.08226912162605804,\n",
       "  0.2551685152843919,\n",
       "  0.19857139478343377,\n",
       "  0.6630193645185498,\n",
       "  0.98097557358107,\n",
       "  0.24531031728045039,\n",
       "  0.5740031343792603,\n",
       "  0.8595337064790686,\n",
       "  0.8407200318039207,\n",
       "  0.48560422346011745,\n",
       "  0.6396213695543025,\n",
       "  0.20140045370979698],\n",
       " [0.6002300437758645,\n",
       "  0.7960485851034023,\n",
       "  0.41160884380024376,\n",
       "  0.9040724645145981,\n",
       "  0.6877882143599552,\n",
       "  0.968184222404837,\n",
       "  0.8188128139969406,\n",
       "  0.8183585764979853,\n",
       "  0.2099547762098133,\n",
       "  0.8456415011235865,\n",
       "  0.6441743403263351,\n",
       "  0.22459448728474907,\n",
       "  0.6794490366659103,\n",
       "  0.14946888733486252,\n",
       "  0.7913733804528483,\n",
       "  0.17700665705099872,\n",
       "  0.10986782448337706,\n",
       "  0.21129210860458592,\n",
       "  0.44059599514986447,\n",
       "  0.5428280426172131,\n",
       "  0.6952499305664699,\n",
       "  0.8130133866437649,\n",
       "  0.3359769329837109,\n",
       "  0.32577549725918076,\n",
       "  0.2919727405239583,\n",
       "  0.9050679632627735,\n",
       "  0.7922927817371463,\n",
       "  0.5288208119434381,\n",
       "  0.5542617839172843,\n",
       "  0.9130218248589902,\n",
       "  0.16608186654180812,\n",
       "  0.5334809940441786],\n",
       " [0.5197604731507227,\n",
       "  0.5561043590364408,\n",
       "  0.21858274178223114,\n",
       "  0.28206893094002816,\n",
       "  0.5083262584097615,\n",
       "  0.5429572258528769,\n",
       "  0.6004918661985947,\n",
       "  0.4116329837210887,\n",
       "  0.7636647248117798,\n",
       "  0.6509808700813229,\n",
       "  0.7638081462907546,\n",
       "  0.8297449394365655,\n",
       "  0.28965727092945426,\n",
       "  0.8456592579728669,\n",
       "  0.37003940232024557,\n",
       "  0.977615021555538,\n",
       "  0.48550769126650095,\n",
       "  0.7374117515797521,\n",
       "  0.7336111045713413,\n",
       "  0.6640071687487586,\n",
       "  0.055596784577331526,\n",
       "  0.7339018217111581,\n",
       "  0.4579401439062972,\n",
       "  0.5772655376912342,\n",
       "  0.5428469744548325,\n",
       "  0.29668566580076794,\n",
       "  0.5805723709948205,\n",
       "  0.5235725267860034,\n",
       "  0.735943864285841,\n",
       "  0.10876970430038613,\n",
       "  0.018230498497457615,\n",
       "  0.7734375461333012],\n",
       " [0.42684633351826917,\n",
       "  0.659879953173634,\n",
       "  0.16329159145752725,\n",
       "  0.07529164663141752,\n",
       "  0.20355453484127672,\n",
       "  0.9369990473029635,\n",
       "  0.7858651213221376,\n",
       "  0.39820454010095474,\n",
       "  0.5470710393301489,\n",
       "  0.9008068149375843,\n",
       "  0.6698041252352199,\n",
       "  0.3851833721413439,\n",
       "  0.9765014014323963,\n",
       "  0.3199128763115754,\n",
       "  0.4922138949741771,\n",
       "  0.8979653278319111,\n",
       "  0.47088132871115607,\n",
       "  0.9089791770957133,\n",
       "  0.9278735097037427,\n",
       "  0.4904044023589501,\n",
       "  0.11616498799124764,\n",
       "  0.3724652159487294,\n",
       "  0.6914360751495782,\n",
       "  0.32283936464373697,\n",
       "  0.14017001451780808,\n",
       "  0.6217001154405317,\n",
       "  0.7400606314935829,\n",
       "  0.30683599385966664,\n",
       "  0.8366357107256828,\n",
       "  0.3301978753835907,\n",
       "  0.1566075586078186,\n",
       "  0.1554108983887844],\n",
       " [0.7036623997715641,\n",
       "  0.9672201124907456,\n",
       "  0.8496383117103039,\n",
       "  0.28417451806233573,\n",
       "  0.42518873833630566,\n",
       "  0.6113270565012405,\n",
       "  0.6632282047978718,\n",
       "  0.2801016519004046,\n",
       "  0.9009033489022973,\n",
       "  0.20610275366460196,\n",
       "  0.44708017199739203,\n",
       "  0.9783311017599835,\n",
       "  0.0973296225113972,\n",
       "  0.6651307328741395,\n",
       "  0.8195015436762834,\n",
       "  0.29135643074884787,\n",
       "  0.5093886113202261,\n",
       "  0.42486755411926824,\n",
       "  0.37673160944727724,\n",
       "  0.9768519774755585,\n",
       "  0.18656424518088144,\n",
       "  0.0695589477608567,\n",
       "  0.8172303378305066,\n",
       "  0.7661720063377843,\n",
       "  0.04829694112511129,\n",
       "  0.6511285364899131,\n",
       "  0.5740726231355241,\n",
       "  0.26018311862917876,\n",
       "  0.7977002116735773,\n",
       "  0.06931832674177651,\n",
       "  0.7351455387494139,\n",
       "  0.11993953813696734],\n",
       " [0.5196733511478511,\n",
       "  0.6336864055086027,\n",
       "  0.20737168361267178,\n",
       "  0.9254947423513502,\n",
       "  0.2418992588834249,\n",
       "  0.9046686886515457,\n",
       "  0.21942123551895654,\n",
       "  0.5472289983852882,\n",
       "  0.38107346220025906,\n",
       "  0.6830089978700749,\n",
       "  0.09473670306292936,\n",
       "  0.621608302517759,\n",
       "  0.29615678009350466,\n",
       "  0.8813316794879426,\n",
       "  0.9813356348137549,\n",
       "  0.42906902669723335,\n",
       "  0.9573750476470935,\n",
       "  0.9672535203879388,\n",
       "  0.8684926236213386,\n",
       "  0.4180127899453945,\n",
       "  0.4209242387608738,\n",
       "  0.15358778815626029,\n",
       "  0.27965902668593423,\n",
       "  0.593851873425696,\n",
       "  0.868660322958078,\n",
       "  0.4195408669980566,\n",
       "  0.5070477301197096,\n",
       "  0.8804328957719022,\n",
       "  0.2880050120497788,\n",
       "  0.44058684666193704,\n",
       "  0.31166357751158413,\n",
       "  0.24267334241739957],\n",
       " [0.16104777099040612,\n",
       "  0.11375834048008016,\n",
       "  0.43398123908474795,\n",
       "  0.28029110566139903,\n",
       "  0.7610044394872858,\n",
       "  0.33568388503117264,\n",
       "  0.8760582522324841,\n",
       "  0.2986124527002706,\n",
       "  0.7748582472418452,\n",
       "  0.952474502736512,\n",
       "  0.6858973501531856,\n",
       "  0.40971971130137474,\n",
       "  0.674705365348447,\n",
       "  0.9233338917385392,\n",
       "  0.3157998985222277,\n",
       "  0.8836630746451947,\n",
       "  0.7423658897490842,\n",
       "  0.49928684357497033,\n",
       "  0.404733064618505,\n",
       "  0.8737664287707343,\n",
       "  0.3856131703881325,\n",
       "  0.6339696660521057,\n",
       "  0.022944441813970595,\n",
       "  0.5866358586553251,\n",
       "  0.30475170347567715,\n",
       "  0.5829605859903307,\n",
       "  0.991717715556096,\n",
       "  0.7604610856028776,\n",
       "  0.126374677962115,\n",
       "  0.20028580732085488,\n",
       "  0.7228809784900233,\n",
       "  0.9060941229511603],\n",
       " [0.38752716128817766,\n",
       "  0.8205847717097242,\n",
       "  0.9652453300525118,\n",
       "  0.47434609397700767,\n",
       "  0.6245943709154675,\n",
       "  0.6097662148941382,\n",
       "  0.4428448844763847,\n",
       "  0.8530351642439662,\n",
       "  0.29781798423695405,\n",
       "  0.09186739514993703,\n",
       "  0.2754444196518038,\n",
       "  0.07378489491978835,\n",
       "  0.6376797608987497,\n",
       "  0.7798078635744445,\n",
       "  0.6546730063390509,\n",
       "  0.3218012342268508,\n",
       "  0.09653723336613651,\n",
       "  0.7490397689486638,\n",
       "  0.3610615549332833,\n",
       "  0.3612232077429569,\n",
       "  0.22106596987478888,\n",
       "  0.8310112918473526,\n",
       "  0.9203749472375917,\n",
       "  0.24543521805154278,\n",
       "  0.6800098334849112,\n",
       "  0.3238517661280579,\n",
       "  0.7537933206861461,\n",
       "  0.7429006827511632,\n",
       "  0.9032625223428101,\n",
       "  0.7124309833307626,\n",
       "  0.817290194883349,\n",
       "  0.9961518120953929],\n",
       " [0.7377376962953552,\n",
       "  0.775413096183397,\n",
       "  0.6511607574399775,\n",
       "  0.7255830358809932,\n",
       "  0.48294892441210413,\n",
       "  0.2085383357329592,\n",
       "  0.8541307813407766,\n",
       "  0.8501706560303198,\n",
       "  0.7044139546507603,\n",
       "  0.32976919640843194,\n",
       "  0.1011325640698123,\n",
       "  0.16670580973840188,\n",
       "  0.8047505572172241,\n",
       "  0.9263653475237743,\n",
       "  0.105893290068372,\n",
       "  0.6325362214931859,\n",
       "  0.09549492963487016,\n",
       "  0.47409647667803523,\n",
       "  0.787296700078053,\n",
       "  0.4307684171127987,\n",
       "  0.5694303689788973,\n",
       "  0.6799533305931091,\n",
       "  0.3149816908227395,\n",
       "  0.7778711078001712,\n",
       "  0.13523742050295706,\n",
       "  0.6614511982532401,\n",
       "  0.7648561835821485,\n",
       "  0.22948119788540344,\n",
       "  0.7135655978999643,\n",
       "  0.39223760936144825,\n",
       "  0.5185309751828353,\n",
       "  0.5023908954318431]]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_input"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[-1.18497694], [0.0344912149], [-0.119354866], [0.71193248], [0.207333058], [0.717658937], [0.428872854], [0.178136736], [0.258845478], [0.210190967]]\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "headers = {\"content-type\": \"application/json\"}\n",
    "json_response = requests.post('http://localhost:8501/v1/models/test:predict', data=data, headers=headers)\n",
    "predictions = json.loads(json_response.text)['predictions']\n",
    "print(predictions)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
